<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">方案名称</div>
                <el-input v-model="search.keywords" placeholder="请输入方案名称" clearable @change="upsearch"></el-input>
                <div class="search-input">巡检人员</div>
                <el-input v-model="search.admin1" placeholder="请输入巡检人员" clearable @change="upsearch"></el-input>
                <el-date-picker v-model="time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size" />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-header>
            <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'xunPlan.add'">新增巡检方案</el-button>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border>
                <el-table-column type="selection" width="50" align="center"></el-table-column>
                <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                <el-table-column label="方案编号" prop="code" align="center"></el-table-column>
                <el-table-column label="方案名称" prop="title" align="center"></el-table-column>
                <el-table-column label="巡检人员" prop="other_name" align="center"></el-table-column>
                <el-table-column label="计划名称" prop="plan_title" align="center"></el-table-column>
                <el-table-column label="开始时间" prop="start_time" align="center"></el-table-column>
                <el-table-column label="结束时间" prop="end_time" align="center"></el-table-column>
                <el-table-column label="状态" prop="plan_title" align="center">
                    <template #default="{row}">
                        <el-tag v-if="row.new_state==0" type="warning">未开始</el-tag>
                        <el-tag v-if="row.new_state==1" type="success">执行中</el-tag>
                        <el-tag v-if="row.new_state==2" type="danger">已关闭</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" align="center">
<!--                    <template #default="{row}">-->
<!--                        <el-popover placement="top-start" :width="200" trigger="hover" :content="row.remark">-->
<!--                            <template #reference>-->
<!--                                <el-button style="padding: 5px 0;" text class="m-2">{{row.remark.substring(0, 8)}}</el-button>-->
<!--                            </template>-->
<!--                        </el-popover>-->
<!--                    </template>-->
                </el-table-column>
                <el-table-column label="操作" align="center" width="180">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'xunPlan.edit'">编辑</el-button>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                <template #reference>
                                    <el-button text type="danger" size="small" v-auth="'xunPlan.delete'">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></save>
</template>

<script>
import save from './save.vue';

export default {
  components: { save },
	name: "user",
	data() {
		return {
            dialog: {
				save: false
			},
			selection: [],
            apiObj: this.$API.device.InspectionProject.lists,
			search:{
                keywords:null,
                device_keywords:null,
                start_time:null,
                end_time:null,
            },
            time:""
		};
	},
	watch: {},
	mounted() { },
	methods: {
        add() {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("add");
			});
		},
        table_edit(row) {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(row);
			});
		},
        //删除
		async table_del(row, index) {
			var reqData = { id: row.id };
			var res = await this.$API.device.InspectionProject.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
                this.$refs.table.refresh();
				this.$message.success("删除成功");
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		},
        //本地更新数据
		handleSuccess(data, mode) {
			if (mode == "add") {
				this.$refs.table.refresh();
			} else if (mode == "edit") {
				this.$refs.table.refresh();
			}
		},
        // 搜索
        upsearch() {
            if(this.time!=null){
                this.search.start_time = this.time[0]
                this.search.end_time = this.time[1]
            }else{
                this.search.start_time = ""
                this.search.end_time = ""
            }
			this.$refs.table.upData(this.search)
		},
	},
};
</script>

<style></style>
